<?php

 /*
  * see setlocale PHP native function
  *
  */    
 
namespace RedMVC;

/**
 * Locale class
 *  
 * @category    RedMVC
 * @author      Jan Fischer, bitWorking <info@bitworking.de>
 */
class Locale{

    protected static $_locale;
    
    public static function get(){
        if(null !== self::$_locale){
            return self::$_locale;
        }
        if(isset(Session::getInstance()->locale)){
            self::$_locale = Session::getInstance()->locale;
        }
        else{
            $config = Registry::get('RedMVC_Config');
            self::$_locale = $config->defaultLocale;
        }
        return self::$_locale;
    }
    
    public static function set($locale){
        $config = Registry::get('RedMVC_Config');
        if(!in_array($locale, $config->validLocales)){
            $locale = $config->defaultLocale;
        }
        self::$_locale                  = $locale;
        Session::getInstance()->locale  = $locale;
        Registry::set('RedMVC_Locale', $locale);
    }


}